package com.hznu.ez4life.modules.controller;


import com.hznu.ez4life.modules.entity.Helpapply;
import com.hznu.ez4life.modules.service.HelpapplyService;
import com.hznu.ez4life.myBeans.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author DragonDoor
 * @since 2019-07-25
 */
@RestController
@EnableAutoConfiguration
@RequestMapping("/helpapply")
public class HelpapplyController {

    @Autowired
    HelpapplyService helpapplyService;

    @PostMapping("/addOne")
    public R addOne(@RequestBody Helpapply helpapply)
    {
        try
        {
            helpapplyService.addOne(helpapply);
            return R.ok();
        }catch (Exception e)
        {
            e.printStackTrace();
            return R.error();
        }
    }

    @GetMapping("/findOne/{id}")
    public R findOne(@PathVariable Integer id)
    {
        try
        {
            return R.ok().put("helpapply",helpapplyService.findOne(id));
        }catch (Exception e)
        {
            e.printStackTrace();
            return R.error();
        }
    }

    @PostMapping("/modifyById")
    public R modifyById(@RequestBody Helpapply helpapply)
    {
        try
        {
            helpapplyService.updateById(helpapply);
            return R.ok();
        }catch (Exception e)
        {
            e.printStackTrace();
            return R.error();
        }
    }

    @GetMapping("/agree/{id}")
    public R agreeApply(@PathVariable Integer id)
    {
        try
        {
            helpapplyService.agreeApply(id);
            return R.ok();
        }catch (Exception e)
        {
            e.printStackTrace();
            return R.error();
        }
    }

    @GetMapping("/findApplyList/{huserId}")
    public R findApplyList(@PathVariable Integer huserId)
    {
        try
        {
            return R.ok().put("helpapplyList",helpapplyService.findBatchByHuserId(huserId));
        }catch (Exception e)
        {
            e.printStackTrace();
            return R.error();
        }
    }
}

